package com.mayflygeek.mayflyask.framework.webmvc.message;

import com.google.common.base.MoreObjects;

/**
 * @author 虫虫
 * @team 蜉蝣极客
 * @link www.mayflygeek.com
 * @Emial chongchong@mayflygeek.com
 * 
 */
public class Message {
	private final MessageType type;

	private final String text;

	private final String detail;

	private final Object data;

	public Message(MessageType type, String text) {
		this(type, text, "", null);
	}

	public Message(MessageType type, String text, String detail) {
		this(type, text, detail, null);
	}

	public Message(MessageType type, String text, String detail, Object data) {
		this.type = type;
		this.text = text;
		this.detail = detail;
		this.data = data;
	}

	public MessageType getType() {
		return type;
	}

	public String getText() {
		return text;
	}

	public String getDetail() {
		return detail;
	}

	public Object getData() {
		return data;
	}

	/**
	 * 是否为操作成功信息
	 * 
	 * 除type为error之外，都认为是
	 */
	public boolean isSuccess() {
		return this.type != MessageType.error;
	}

	@Override
	public String toString() {
		return MoreObjects.toStringHelper(this).add("type", type).add("text", text).add("detail", detail)
				.add("data", data).add("success", isSuccess()).toString();
	}

}
